﻿using ProjectCore.Application.AppUser.Dto;
using ProjectCore.Domain.Repository.Interfaces;
using ProjectCore.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;
using ProjectCore.Domain.Model.Entity;
using System.Linq;
using ProjectCore.Domain.DomainService;
using System.Threading.Tasks;

namespace ProjectCore.Application
{
    public class AppProduct : IAppProduct
    {
        private readonly IBaseRepository<PproductType> baseRepository;
        private readonly MyContext myContext;
        private readonly IProductDomainService product1;
        public AppProduct(IBaseRepository<PproductType> _baseRepository, MyContext _myContext, IProductDomainService _productDomainService)
        {
            baseRepository = _baseRepository;
            myContext = _myContext;
            product1 = _productDomainService;
        }


        //商品添加
        public async Task<int> Add(Product product)
        {
            return await product1.Add(product);
        }


        //反填
        public async Task<Product> GetProduct(int Id)
        {
            return await product1.GetProduct(Id);
        }


        //商品显示
        public async  Task<List<PproductType>> GetPproductTypes()
        {
            var l = from a in myContext.Products
                    join b in myContext.ProductTypes
                    on a.TypeID equals b.ProTypeID
                    join c in myContext.PicUrls
                    on a.Photo equals c.ID
                    select new PproductType
                    {
                        ProID = a.ProID,
                        Photo = c.Photo,
                        ProName = a.ProName,
                        ProTypeName = b.ProTypeName,
                        Sales = a.Sales,
                        Sort = a.Sort,
                        State = a.State,
                        CreateTime = a.CreateTime
                    };
            return await l.ToListAsync();

        }


        //商品逻辑删除
        public async Task<int> IsDel(int Id)
        {
            return await product1.IsDel(Id);
        }
        
        
        //其他设置添加
        public async Task<int >SettingAdd(Setting setting)
        {
            return await product1.SettingAdd(setting);
        }


        //其他设置反填
        public async Task<Setting> GetSetting(int Id)
        {
            return await product1.GetSetting(Id);
        }


        //其他设置修改
        public async Task<int> SettingUpt(Setting setting)
        {
            return await product1.SettingUpt(setting);
        }


        //汽车Sku添加
        public async Task<int> SkuCarAdd(SkuCar car)
        {
            return await product1.SkuCarAdd(car);
        }


        //汽车Sku反填
        public async Task<SkuCar> GetCar(int Id)
        {
            return await product1.GetCar(Id);
        }


        //汽车Sku修改
        public async Task<int> SkuCarUpt(SkuCar car)
        {
            return await product1.SkuCarUpt(car);
        }


        //手机Sku添加
        public async Task<int> SkuPhoneAdd(SkuPhone phone)
        {
            return await product1.SkuPhoneAdd(phone);
        }


        //手机Sku反填
        public async Task<SkuPhone> GetPhone(int Id)
        {
            return await product1.GetPhone(Id);
        }


        //手机Sku修改
        public async Task<int> SkuPhoneUpt(SkuPhone phone)
        {
            return await product1.SkuPhoneUpt(phone);
        }


        //修改
        public async Task<int> Upt(Product product)
        {
            return await product1.Upt(product);
        }



    }
}
